package Game;

import java.awt.event.*;

import View.BoardPanel;
import AI.*;

public class MouseAction extends MouseAdapter{
	public int ix,iy,color;
//	private boolean clicked;
	private GameController gc;
	private Human human;
	private cudaAI cai;
	
	static
    {
            System.loadLibrary("TopAI");
    }
	
	public MouseAction(Pieces p,BoardPanel bP,Human human) {
		pieces = p;
		bPanel = bP;
		this.human=human;
		ix=iy=0;
		cai = new cudaAI();
	}
	
	public void mouseClicked(MouseEvent e) {
		int x = e.getX()-BoardPanel.leftX;
		int y = e.getY()-BoardPanel.leftY;
		int dx = Pieces.dimX-1;
		int dy = Pieces.dimY-1;
		
		int gx = BoardPanel.gridW;
		int gy = BoardPanel.gridH;
		
		if(x<0 || x>dx*gx || y<0 || y>dy*gy) {
			return;
		}
		
		ix = (x+gx/2)/gx;
		iy = (y+gy/2)/gy;
		
		int j = cai.nextStep(pieces.toArr(), 0, 0, 0);
		human.notifyControllor(ix,iy);
	}
	

	
//	public void playerTurn(int ix, int iy) {
//		
//
//
//		if(pieces.getOnePiece(ix, iy)==Pieces.BLANK) {
//			pieces.setOnePiece(ix, iy);
//			if(rule.isWin()){
//				bPanel.hasWon = true;
//			
//			}
////			else{
////				boolean white = true;
////				if(pieces.lastColor == -1){
////					white = false;
////				}
////				int result = evaluate.evaluate(pieces.getPieces(), white);
////				System.out.println(result);
////			}
//			OneStep step = ai.getNextStep();
//			pieces.setOnePiece(step.x, step.y);
//			if(rule.isWin()){
//				bPanel.hasWon = true;
//			
//			}
//			bPanel.repaint();
//		}
//	}
	
	private Rule rule;
	private Pieces pieces;
	private BoardPanel bPanel;
	private AI ai;
}
